var pop_parentDocument = false;
try{
	pop_parentDocument = window.parent.location.href != window.location.href ? window.parent.document : null;
}catch(e){}
/*
 * top：默认为100，auto为正居中弹出
 * isShield：是否有屏蔽
 */
function openPopDiv(popdiv_inner, url, top, isShield) {
	if(top == "auto"){
		top = "50%";
	}else if(!top || (isNaN(top) && top.indexOf('px') < 0)){
		top = "100px";
	}else if(!isNaN(top)){
		top = top + "px";
	}
	var div = $("#"+popdiv_inner);
	var shieldDiv = $("#popdiv_outter");
	if(shieldDiv.length == 0){
		$("body").prepend('<div id="popdiv_outter" class="popdiv_outter"></div>')
		shieldDiv = $("#popdiv_outter");
	}
	var parentShield = $(pop_parentDocument).find('#popdiv_outter');
	if(pop_parentDocument && parentShield.length == 0){
		$(pop_parentDocument).find("body").prepend('<div id="popdiv_outter" class="popdiv_outter" style="z-index:5000"></div>');
		parentShield = $(pop_parentDocument).find('#popdiv_outter');
	}
	/*
	div.unbind("click.popdiv").bind("click.popdiv",function(){
		$("div[popDiv]").css({'z-index':'9998'});
		div.css({'z-index':'9999'});
	})
	*/
	
	var openDiv = function(){
		div.attr("popDiv",isShield != false ? 1 : 2); //记录弹出的层
		$("div[popDiv]").css({'z-index':'9998'});
		div.css({'position':'absolute','left':'50%','top':top,'margin-left':'-' + (div.width()/2) + 'px','z-index':'9999'});
		if(top == "50%"){
			div.css("margin-top",'-' + div.height()/2 + 'px');
		}
		if(isShield != false){ //弹出灰色屏蔽层
			shieldDiv.bgiframe().show();
			parentShield.bgiframe().show();
		}
		div.bgiframe().show();
		divMoveG(div.find('.popdiv_handle'), div);
		
		var closeDiv = div.find(".popdiv_close");
		if(closeDiv.length > 0){
			closeDiv.css('cursor','pointer')
			closeDiv.unbind("click.closediv").bind("click.closediv",function(){
				div.attr("popDiv","0");
				if(isShield != false && $("div[popDiv=1]:visible").length == 0){
					shieldDiv.hide();
					parentShield.hide();
				}
				div.hide();
			})
		}
	}
	if(url && url != ""){
		div.find('.popdiv_content').html("<img src='"+prefix+"images/loading.gif' class='loading'/>");
		$.post(url, null, function(data){
			div.find('.popdiv_content').html(data);
			openDiv()
		});
	}else{
		openDiv()
	}
}
//关闭弹窗
function hidePopDiv(popdiv_inner){
	var closeDiv = $('#'+popdiv_inner).find(".popdiv_close");
	if(closeDiv.length > 0){  //关闭其它窗口
		if(document.all){
			closeDiv[0].click();  
		}else{  
			var evt = document.createEvent("MouseEvents");  
			evt.initEvent("click", true, true);  
			closeDiv[0].dispatchEvent(evt);  
		} 
	}else{
		$(this).hide();
		$(this).attr("popDiv","0"); //记录弹出的层
		$(pop_parentDocument).find('#popdiv_outter').hide();
	}
}
//只打开一个弹窗，关闭其它弹窗
function openOnePopDiv(popdiv_inner, url, top, isShield) {
	$("div[popDiv]:visible").each(function(){  //关闭弹出的div
		var closeDiv = $(this).find(".popdiv_close");
		if(closeDiv.length > 0){  //关闭其它窗口
			if(document.all){
				closeDiv[0].click();  
			}else{  
				var evt = document.createEvent("MouseEvents");  
				evt.initEvent("click", true, true);  
				closeDiv[0].dispatchEvent(evt);  
			} 
		}else{
			$(this).hide();
			$(this).attr("popDiv","0"); //记录弹出的层
		}
	});
	openPopDiv(popdiv_inner, url, top, isShield);
}

function closePopDiv(popdiv_inner){
	var closeDiv = $('#' + popdiv_inner).find(".popdiv_close");
	if(closeDiv.length > 0){
		closeDiv[0].click();
	}
}

function divMoveG(childNode,parentNode){
	var parentWidth = $(parentNode).width();
    $(parentNode).width(parentWidth);
    $(childNode).mousedown(function(e){
		$("div[popDiv=1]").css({'z-index':'9998'});
		$(parentNode).css({'z-index':'9999'});//控件新位置
		var _x=e.pageX-parseInt($(parentNode).position().left);
		var _y=e.pageY-parseInt($(parentNode).position().top);
		$(document).unbind('mousemove.moveG');
		$(document).bind('mousemove.moveG',function(e){
			var x=e.pageX-_x;//移动时根据鼠标位置计算控件左上角的绝对位置
			var y=e.pageY-_y; 
			x = x < parentWidth/2 ? parentWidth/2 : x;
			y = y < 0 ? 0 : y;
			$(parentNode).css({'top':y,'left':x});//控件新位置
		})
		$(document).mouseup(function(){
			$(document).unbind('mousemove.moveG');
		});
    });
    $(childNode).mouseover(function(e){this.style.cursor="move";});
}